package com.ruoyi.web.controller.wxauthor;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.AuthUtil;
import com.ruoyi.web.controller.config.WxConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @Description: TODO
 * @Author ONESTAR
 * @Date: 2021/7/10 17:04
 * @Version 1.0
 */
@Controller
@RequestMapping("/wxLogin")
@CrossOrigin
public class wxLoginController {

    // Step1 引导用户进行授权
    @RequestMapping("/code")
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String backUrl = WxConfig.SERVER_BASE_URL + "/callBack/getUserInfo";
        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                "appid=" + WxConfig.APPID +
                "&redirect_uri=" + URLEncoder.encode(backUrl) +
                "&response_type=code" +
                "&scope=snsapi_userinfo" +
                "&state=STATE#wechat_redirect ";
        resp.sendRedirect(url);
    }


}
